package com.java.controller;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.java.entity.RaceAdmin;
import com.java.entity.RaceCourse;
import com.java.entity.event.RaceCourseEvent;
import com.java.service.RaceCourseService;
import com.java.util.resp.BaseRespone;
import com.java.util.resp.TableRespone;
import com.java.util.servlet.ServletUtil;

@RestController
//@RequestMapping("/course")
public class RaceCourseController {

	@Autowired
	RaceCourseService courseService;

	@PostMapping("/saveCourse")
	public BaseRespone saveCourse(@RequestBody RaceCourse course) {
		course.setCourseUserId(ServletUtil.getUserId(null));
		return courseService.saveCourse(course);
	}

	@PostMapping("/updateCourse")
	public BaseRespone updateCourse(@RequestBody RaceCourse course) {
		return courseService.updateCourse(course);
	}

	@PostMapping("/delCourse")
	public BaseRespone delCourse(@RequestParam(required = false) String courseId) {
		return courseService.delCourse(courseId);
	}
	
	@PostMapping("/getCourses")
	public TableRespone getCourses(
			@RequestParam(required = false) String userId,
			@RequestParam(required = false, defaultValue = "0") int page,
			@RequestParam(required = false, defaultValue = "0") int size) {
		return courseService.getRaceCourses(ServletUtil.getUserId(userId), page, size);
	}
	
	@PostMapping("/getCourse")
	public RaceCourseEvent getCourse(
			@RequestParam(required = false) String courseId) {
		return courseService.getCourse(courseId);
	}
	
	

	@PostMapping("/saveApply")
	public BaseRespone saveApply(
			@RequestParam(required = false) String userId,
			@RequestParam(required = false) String courseId) {
		return courseService.saveApply(ServletUtil.getUserId(userId), courseId, null);
	}
	
	@PostMapping("/saveApplyFile")
	public BaseRespone saveApplyFile(
			@RequestParam(required = false) String applyId,
			@RequestParam(required = false) String file) {
		return courseService.saveApplyFile(applyId, file);
	}

	@PostMapping("/giveupApply")
	public BaseRespone giveupApply(@RequestParam(required = false) String applyId) {
		return courseService.giveupApply(applyId);
	}

	@PostMapping("/passApply")
	public BaseRespone passApply(@RequestParam(required = false) String applyId) {
		return courseService.passApply(applyId);
	}

	@PostMapping("/applyScore")
	public BaseRespone applyScore(@RequestParam(required = false) String applyId,
			@RequestParam(required = false) BigDecimal score) {
		return courseService.applyScore(applyId, score);
	}

	@PostMapping("/applyGuide")
	public BaseRespone applyGuide(@RequestParam(required = false) String applyId,
			@RequestParam(required = false) String applyGuide,
			@RequestParam(required = false) String applyGuideFile) {
		return courseService.applyGuide(applyId, applyGuide, applyGuideFile);
	}

	@PostMapping("/applyDelete")
	public BaseRespone applyDelete(@RequestParam(required = false) String applyId) {
		return courseService.applyDelete(applyId);
	}
	
	@PostMapping("/getApplys")
	public TableRespone getApplys(
			@RequestParam(required = false) String userId,
			@RequestParam(required = false) Integer status,
			@RequestParam(required = false, defaultValue = "0") int page,
			@RequestParam(required = false, defaultValue = "0") int size) {
		return courseService.getApplys(ServletUtil.getUserId(userId), status, page, size);
	}
	
	@PostMapping("/getTeacherApplys")
	public TableRespone getTeacherApplys(
			@RequestParam(required = false) String userId,
			@RequestParam(required = false) Integer status,
			@RequestParam(required = false, defaultValue = "0") int page,
			@RequestParam(required = false, defaultValue = "0") int size) {
		return courseService.getTeacherApplys(ServletUtil.getUserId(userId), status, page, size);
	}
}
